# Define here the models for your scraped items
#
# See documentation in:
# https://docs.scrapy.org/en/latest/topics/items.html

import scrapy

from components.custom_item import UpdateCustomItem


class NetDataStatsItem(UpdateCustomItem):
    __table_name__ = 'net_data_stats'
    __update_key__ = [
        "cate_1",
        "cate_2",
        "cate_3",
        "cate_4",
        "area",
        "tag_name",
        "date_string",
        "data_type",
        "num",
        "num_string",
        "unit",
        "source",
    ]

    cate_1 = scrapy.Field()
    cate_2 = scrapy.Field()
    cate_3 = scrapy.Field()
    cate_4 = scrapy.Field()
    area = scrapy.Field()
    tag_name = scrapy.Field()
    date_string = scrapy.Field()
    data_type = scrapy.Field()
    num = scrapy.Field()
    num_string = scrapy.Field()
    unit = scrapy.Field()
    source = scrapy.Field()

    def pre_to_db(self):
        self.cate_1 = self.cate_1 or ''
        self.cate_2 = self.cate_2 or ''
        self.cate_3 = self.cate_3 or ''
        self.cate_4 = self.cate_4 or ''
        self.area = self.area or ''
        self.tag_name = self.tag_name or ''
        self.date_string = self.date_string or ''
        self.data_type = self.data_type or ''
        self.num = self.num or 0
        self.num_string = self.num_string or ''
        self.unit = self.unit or ''
        self.source = self.source or '国家统计局'
